<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  admin_activity.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-19.
//  Copyright 2011 lishuzu. All rights reserved.
// 

class Admin_work extends CI_Controller {

	 function __construct()
	 {
		parent::__construct();
 		$this->load->model('common/security_model');
		if($this->security_model->isAdminLogin() === FALSE){
          showmessage('请登录', 'admin/login/index', 3);
		}
 		$this->load->model('admin_work_model');
 		$this->load->model('work_model');
		$this->load->library('user_agent');
	 }

	function index()
	{
		$data = array();
		$data = $this->admin_work_model->get_list();
		$this->load->template('admin/admin_work_tpl', $data);
	}
	
	// 批量处理
	function batchop(){
		$setarr = array();
		$wids = $this->input->post('ids', true);
		$optype = intval($this->input->post('optype', true));
		$refer = $this->input->post('refer') ? $this->input->post('refer') : 'admin/admin_work/index';
		// 更新购买信息
		if (submitcheck('shopsubmit')) {
			if (!$wids) {
				showmessage('未选择作品', $refer, 2);
			}
			$totalnum = $this->input->post('totalnum', true);
			$soldoutnum = $this->input->post('soldoutnum', true);
			$shopurl = $this->input->post('shopurl', true);
			$price = $this->input->post('price', true);
			$reserve = $this->input->post('reserve', true);
			foreach ($wids as $wid) {
				$setarr = array(
					'wid' => $wid,
					'totalnum' => $totalnum[$wid],
					'soldoutnum' => $soldoutnum[$wid],
					'shopurl' => $shopurl[$wid],
					'price' => $price[$wid],
					'reserve'=>$reserve[$wid],
					);
				if ($setarr) {
					$this->work_model->update($setarr);
				}
			}
			showmessage('更新成功', $refer, 2);
		}
		
		// 批量操作
		if (submitcheck('listsubmit')) {
			if (!$wids) {
				showmessage('未选择作品', $refer, 2);
			}
			if (!$optype) {
				showmessage('未选择操作', $refer, 2);
			}
			switch ($optype) {
					// 审核作品
				case '1':
					$data =  array('status' => '1');
					$this->work_model->updates($wids,$data);
					break;
					// 重新审核
				case '2':
					$data =  array('status' => '0');
					$this->work_model->updates($wids,$data);
					break;
					// 推荐作品
				case '3':
					$data =  array('status' => '2');
					$this->work_model->updates($wids,$data);
					break;
					// 取消推荐
				case '4':
					$data =  array('status' => '1');
					$this->work_model->updates($wids,$data);
					break;
					// 恢复删除
				case '5':
					$this->work_model->revert($wids);
					break;
					// 彻底删除
				case '6':
					$this->work_model->delete($wids);
					break;
			}
			showmessage('操作成功', $refer, 2);
		}
		
		showmessage('您的操作不正确', $refer, 2);
	}
}
?>